package offline

import (
	"fmt"

	lcli "github.com/filecoin-project/lotus/cli"
	"github.com/urfave/cli/v2"
	"golang.org/x/xerrors"
)

var BaseFeeCmd = &cli.Command{
	Name:  "base-fee",
	Usage: "print base fee",
	Flags: commonFlag,
	Action: func(cctx *cli.Context) error {
		api, acloser, err := lcli.GetFullNodeAPI(cctx)
		if err != nil {
			return err
		}
		defer acloser()
		ctx := lcli.ReqContext(cctx)
		ts, err := api.ChainHead(ctx)
		if err != nil {
			return xerrors.Errorf("failed to get chain head: %w", err)
		}

		baseFee := ts.Blocks()[0].ParentBaseFee
		fmt.Printf("%s\n", baseFee)
		return nil
	},
}
